﻿@using Huirui.Cavan.Domain.MainBoundedContext.SystemModule
@model Huirui.Cavan.Presentation.ViewModel.SystemModule.ISupplierViewModel
@{Layout = null;}
@using (Html.BeginForm(ActionConst.ADD, ControllerConst.SUPPLIER))
{ 
    <div class="tool_bar">
        <input id="supplier_save" type="submit" style="display: none;" />
        <input id="suply_reset" type="reset" style="display: none" />
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'" onclick="javascript:$('#supplier_save').click()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'"
            onclick="addTab('供应商档案列表','center_tt','@Url.Action(ActionConst.LIST, ControllerConst.SUPPLIER)')">查询</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-undo'" id="supplier_reset">重置</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-collapse'" onclick="toggleHeard()">折叠/展开</a>
    </div>
    <table class="form_heard">
        <tr>
            <td class="c100">
                <label class="BlueRequired">编号:</label>
            </td>
            <td class="c160">
                @{
    var createTypeList = new List<SelectListItem>();
    createTypeList.Add(new SelectListItem() { Selected = true, Text = "自动生成", Value = "1" });
    createTypeList.Add(new SelectListItem() { Text = "手工输入", Value = "0" });
                }
                <table class="form_heard" style="border-collapse: collapse">
                    <tr>
                        <td class="c80" style="padding: 0">
                            @Html.DropDownList("supplierid_type", createTypeList)
                        </td>
                        <td class="c80">
                            @Html.TextBoxFor(m => m.NoPrefixId, new { id = "supplier_NoPrefixId" })
                            @Html.HiddenFor(m => m.Item.Id, new { id = "supplier_Id" })
                        </td>
                    </tr>
                </table>
            </td>
            <td class="c100">
                <label>业务员:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.EmployeeRole, typeof(SystemIdentifier.Role), new { id = "supplier_employeerole" })
            </td>
            <td class="c160">
            </td>
        </tr>
        <tr>
            <td class="c100">
                <label class="BlueRequired">名称:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Name, new { id = "supplier_name" })
            </td>
            <td class="c100">
                <label class="BlueRequired">供应商性质:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.Nature, typeof(SystemIdentifier.SupplierNature), new { id = "supplier_nature" })
            </td>
            <td class="c160">
            </td>
        </tr>
        <tr>
            <td class="c100">
                <label>类别:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.Item.Type.Id, Model.SupplierTypes, new { id = "supplier_type" })
            </td>
            <td class="c100">
                <label>所属地区:</label>
            </td>
            <td colspan="2">
                @Html.Action(ActionConst.SELECTAREA, ControllerConst.AREA, new { purpose = "ForSupplier", cityID = @Model.CityID, provinceID = @Model.ProvinceID })
                @Html.HiddenFor(m => m.Item.Area.Id, new { id = "areaForSupplier" })
            </td>
        </tr>
        <tr>
            <td class="c100">
                <label>备注:</label>
            </td>
            <td colspan="4">
                @Html.TextBoxFor(m => m.Item.Remark, new { id = "supplier_remark" })
            </td>
        </tr>
    </table>
    <fieldset>
        <legend>联系方式</legend>
        <table class="form_heard">
            <tr>
                <td class="c100">
                    <label>联系人:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Contact, new { id = "supplier_contact" })
                </td>
                <td class="c100">
                    <label>电话号码:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Telephone, new { id = "supplier_telephone" })
                </td>
                <td class="c100">
                </td>
                <td class="c160">
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>手机号码:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Mobile, new { id = "supplier_mobile" })
                </td>
                <td class="c100">
                    <label>传真号码:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Fax, new { id = "supplier_fax" })
                </td>
                <td class="c100">
                    <label>Email:</label>
                </td>
                <td class="c160">
                    @Html.TextBoxFor(m => m.Item.Email, new { id = "supplier_email" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>通讯地址(中文):</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.Address, new { id = "supplier_address" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>通讯地址(英文):</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.AddressEnglish, new { id = "supplier_addressenglish" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>送货地址1:</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.DeliveryAddress1, new { id = "supplier_deliveryaddress1" })
                </td>
            </tr>
            <tr>
                <td class="c100">
                    <label>送货地址2:</label>
                </td>
                <td colspan="5">
                    @Html.TextBoxFor(m => m.Item.DeliveryAddress2, new { id = "supplier_deliveryaddress2" })
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>会计属性</legend>
        <table class="form_heard">
            <tr>
                <td class="c100">
                    <label>付款方式:</label>
                </td>
                <td class="c160">
                    @Html.DropDownListFor(m => m.PayType, typeof(SystemIdentifier.PayType), new { id = "supplier_paytype" })
                </td>
                <td class="c100">
                    <label>折扣率:</label>
                </td>
                <td class="c50">
                    @Html.TextBoxFor(m => m.Item.DiscountRate, new { id = "supplier_discountrate" })
                </td>
                <td class="c100">
                    <label>账期[天]:</label>
                </td>
                <td class="c50">
                    @Html.TextBoxFor(m => m.Item.PayDay, new { id = "supplier_payday" })
                </td>
                <td class="c100">
                    <label>信用额度:</label>
                </td>
                <td class="c100">
                    @Html.TextBoxFor(m => m.Item.CreditLimit, new { id = "supplier_creditlimit" })
                </td>
                <td class="c100">
                    <label>默认税率:</label>
                </td>
                <td class="c50">
                    @Html.TextBoxFor(m => m.Item.DefaultTaxRate, new { id = "supplier_defaulttaxrate" })
                </td>
                <td class="c10">
                    @Html.Raw("%")
                </td>
            </tr>
        </table>
    </fieldset>
}
@{ Html.RenderAction(ActionConst.ADD, ControllerConst.SUPPLIERTYPE, new { Purpose = "ForSupplier", CmbName = "select#supplier_type" }); }
<fieldset>
    <legend>维护其它信息</legend>
    <div class="customer_div">
        <a>应收款初始余额:</a>
        <a>销售信息维护</a>
    </div>
</fieldset>
<script type="text/javascript">
    $("#supplier_NoPrefixId").attr("disabled", true);
    $("select#supplierid_type").bind("change", function ()
    {
        if ($(this).val() == "1")
        {
            $("#supplier_NoPrefixId").attr("disabled", true);
        }
        else
        {
            $("#supplier_NoPrefixId").attr("disabled", false);
        }
    });

    $("#supplier_reset").bind("click", function ()
    {
        $('#suply_reset').click();
        if ($('select#supplierid_type').val() == "1")
        {
            $("#supplier_NoPrefixId").attr("disabled", true);
        }
        else
        {
            $("#supplier_NoPrefixId").attr("disabled", false);
        }
    });

    $("select#supplier_type").bind("change", function ()
    {
        if ($('select#supplier_type').val() == "0")
        {
            openWindow("addSupplierTypeWindowForSupplier");
        }
    });
    

    $(function ()
    {
        $("form[action^='/supplier/add']").submit(function ()
        {
            $("#areaForSupplier").val($("#cityForSupplier").val());  
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (data)
                {
                    if (data.IsSuccess)
                    {
                        alert(data.Messages[0]);
                    }
                },
                error: function ()
                {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });
    });

    $("#provinceForSupplier").bind("change", function () { getSelectItem($("#provinceForSupplier").val(), $("#cityForSupplier")) });
//    $("#cityForSupplier").bind("change", function () { getAreaValue("areaForSupplier", $(this).val()) });
</script>
